<?php

namespace app\index\controller;

class Massage extends Base
{

    public function index($i = false)
    {
        $list = model('Massage')->order('create_time DESC,id DESC')->paginate()->appends($this->request->param());;

        $this->assign(
            ['list' => $list]
        );
        return $this->fetch($this->template . 'Massage.html');
    }

    public function massagedetailed($id)
    {
        $data = model('Massage')->find($id);
        $this->assign(
            ['data' => $data]
        );
//dump($list);
        return $this->fetch($this->template . 'massagedetailed.html');
    }


    /**
     *提交留言
     */
    public function save()
    {
        if ($this->request->isPost()) {

            $data = $this->request->post();

            $result = $this->validate($data, 'Massage');
            if (true !== $result) {
//                $this->error($result);
                return ajax_info($result);
            }
            
            $data['lang'] = cookie('think_var');
            $data['cid'] = isset($data['navid'])?$data['navid']:'0';
            $res = model('Massage')->allowField(true)->save($data);
            if ($res) {
//                $this->success('留言成功，等待审核！');
                return ajax_info('留言成功！', 'y');
            } else {
//                $this->error('留言失败！');

                return ajax_info('留言失败！');
            }

        }

    }

}
